home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The PC-SIG Library 9
/
The PC-SIG Library on CD ROM - Ninth Edition.iso
/
101_200
/
DISK0163
/
DISK0163.ZIP
/
TRANSLIT.C
< prev
next >
Wrap
Text File
|
1983-08-22
|
2KB
|
66 lines
/* translit.c by Michael Hanson */
/* you may use this, but not for profit, and please give me credit */
/* translit character translation program */
#include "stdio.h"
#define MAXSET 300
#define NOT '!'
#define DUMEOF 0x1a
main(argc,argv)
int argc;
char *argv[];
{
int allbut,collap,i,lastto;
int c;
char from[MAXSET],to[MAXSET];
if(ver()<0x200){
error("translit: wrong DOS version",1);
#asm
db 'by Michel Hanson v1.0',1ah
#
}
else if(argc<2)
error("usage: translit from to.",1);
else if(*argv[1] == NOT){
allbut = YES;
if(makset(argv[1],1,from,MAXSET) == NO)
error("from:too large.",1);
}
else {
allbut = NO;
if(makset(argv[1],0,from,MAXSET) == NO)
error("from: too large.",1);
}
if(argc<3)
to[0]=EOS;
else if(makset(argv[2],0,to,MAXSET) == NO)
error("to: too large.",1);
lastto = strlen(to);
collap = (strlen(from) > lastto || allbut == YES) ? YES : NO ;
do{
i= xindex(from,(c = getc(STDIN)),allbut,lastto);
if(collap == YES && i >= lastto && lastto>0){ /* collapse */
putc(to[lastto-1],STDOUT);
do
i = xindex(from,(c = getc(STDIN)),allbut,lastto);
while(i >= lastto);
}
if(c == EOF || c == DUMEOF)
break;
if(i>-1 && lastto>0) /* translate */
putc(to[i],STDOUT);
else if(i == -1) /* copy */
putc((char) c,STDOUT);
}while(TRUE);
}
#include "version.c"
#include "sets.c"
#include "err.c"
#include "inde.c"
#include "filps.c"
#include "esct.c"